<template>
  <!-- 好生活资金池-详情-回款记录-->
  <div class="returnRecordDetail">
    <brokerInfo :infos="info"></brokerInfo>
    <tableList
      :tableData="tableData"
      :tableInfos="tableInfos"
      :tableFormatter="tableFormatter"
      :hasSera="true"
    ></tableList>
  </div>
</template>

<script type="text/ecmascript-6">
import brokerInfo from "./brokerInfo";
import tableList from "../../common/tableList";
import utils from "@/common/utils.js";
import api from "@/api/apiPath";
export default {
  components: {
    brokerInfo,
    tableList
  },
  data() {
    return {
      tableData: [],
      firstFlag: true,
      tableInfos: [
        { label: "批次号", prop: "batchCode" },
        { label: "应回款金额（元）", prop: "brokerageAmountTotal" },
        { label: "已回款金额（元）", prop: "brokerageAmountPaid" },
        { label: "本次回款金额（元）", prop: "brokerageAmountPaying" },
        { label: "未回款金额（元）", prop: "brokerageAmountNoPaid" },
        { label: "提交人", prop: "submitPersonName" },
        { label: "提交时间", prop: "createTime" },
        { label: "佣金结算审核通过时间", prop: "auditTime" },
        { label: "审核状态", prop: "auditStatus" }
      ],
      auditStatusArray: [
        "待提交",
        "待审核",
        "开发商通过审核",
        "开发商审核拒绝",
        "财务审核通过",
        "财务审核拒绝"
      ],
      customerSourceArray: {
        "0":"经纪人录入",
        "1":"运营录入",
        "2":"扫码录入",
        "3":"购房者注册",
        "4":"推荐注册",
        "5":"公众号注册",
        "6":"网络推客录入",
        "7":"微楼盘注册",
        "8":"APP下单",
        "9":"预约看房",
        "11":"网络推客-集团小程序",
        "13":"认购录入"
      },
      info: {}
    };
  },
  created() {},
  mounted() {},
  methods: {
    tableFormatter(prop, val) {
      let moneyFormatter = [
        "brokerageAmountTotal",
        "brokerageAmountPaid",
        "brokerageAmountPaying",
        "brokerageAmountNoPaid"
      ];
      if (moneyFormatter.includes(prop)) {
        return this.formatMoney(val);
      }
      let propMap = {
        auditStatus: this.auditStatusArray
      };
      return propMap[prop] ? propMap[prop][val] : val;
    },
    searchList() {
      this.axios
        .get(api.getCashPoolReturnList + "/" + this.userInfo.orderId)
        .then(res => {
          if (res.data.code == 200) {
            this.firstFlag = false;
            this.tableData = res.data.data;
          }
        });
    },
    formatMoney(val){
      return  val? utils.formatMoney(val)+"元": "0.00 元"
    },
    getUserInfo(val) {
      let {
        customerName,
        customerPhone,
        customerSource,
        devName,
        housePrise,
        actualPayment,
        cellName,
        backBrokerageTotal
      } = val;
      this.info = {
        客户姓名: customerName,
        电话: utils.formatPhoneNumber(customerPhone),
        客户来源: this.customerSourceArray[customerSource],
        楼盘: devName,
        房款:  this.formatMoney(housePrise) ,
        成交价: this.formatMoney(actualPayment) ,
        房间号: cellName,
        "后佣总额（元）": this.formatMoney(backBrokerageTotal)
          
      };
    }
  },
  props: ["userInfo", "active"],
  watch: {
    active(val) {
      if (this.firstFlag && val) {
        this.searchList();
      }
    },
    allInfo(val) {
      this.getUserInfo(val);
    }
  },
  computed: {
    allInfo() {
      return this.userInfo.allInfo;
    }
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="stylus"></style>
